import web
import json
from datetime import datetime

#thanks: http://stackoverflow.com/questions/11875770/how-to-overcome-datetime-datetime-not-json-serializable-in-python
class DateTimeEncoder(json.JSONEncoder):
	def default(self, obj):
		if isinstance(obj, datetime):
			return obj.isoformat()
		return json.JSONEncoder.default(self, obj)

class Base:
	"""A base class that contains a static mysql database connector that connects to our database in the CoC"""
	db = web.database(
		dbn="mysql",
		host="academic-mysql.cc.gatech.edu", 
		db="cs4400_Team_11",
		user="cs4400_Team_11", 
		pw="w01goZoX"
	)
	
	def query_serializer(self, query):
		query = [dict(result) for result in query]
		query = DateTimeEncoder().encode(query)
		return query


